-
Couldn't load subscription status.
- Fork 2.7k
feat: add claims field to AccessToken for decoded token payload #1165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @robertofalk, thanks for sending this PR!
Currently, there is no JWT payload used to build the AccessToken, afaict.
To handle JWT tokens, you might want to create a new JWTAccessToken / created by a new JWTTokenVerifier (responsible for verifying the token signature), used by a JWT-specific OAuthAuthorizationServerProvider subclass distinct from SimpleOAuthProvider.
(and if we get there, I reckon the non-standard claims should go to a JWTAccessToken.additional_claims field to avoid duplication)
Does this make sense?
|
Closing this as per @ochafik's comment this is incomplete and it's been a while since the last update here. If others find this PR and need this, feel free to submit a fresh PR. |
Add optional claims dict to AccessToken class to provide access to all decoded JWT claims (both standard and custom) instead of restricting to only specific fields like scopes and expires_at.
Motivation and Context
FastMCP provides a BearerAuthProvider class to validate bearer tokens and returns it using the AccessToken class (https://github.com/jlowin/fastmcp/blob/main/src/fastmcp/server/auth/providers/bearer.py#L387). With the current implementation the claims from the token are limited to the ones defined so far, so any additional claim is not available and to get it currently I had to define an additional middleware that decodes the token again, which is a waste since the token is was already decoded by BearerAuthProvider.
How Has This Been Tested?
I was not able to test it since it's just an attribute that will be used by applications relying on the python-sdk AccessToken class.
Breaking Changes
No, it's an optional attribute.
Types of changes
Checklist
Resolves #1038